/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.invernadero.Dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itschapala.dsw2.invernadero.modelo.Staff;

/**
 *
 * @author Raven
 */
@Stateless
public class StaffDao extends AbstractDao<Staff> implements StaffDaoLocal {
    @PersistenceContext(unitName = "InvernaderoProject-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StaffDao() {
        super(Staff.class);
    }
    
    @Override
        public boolean findDuplicity(Staff staff) {
        //seleccionar consulta
        Query q= em.createNamedQuery("Staff.findDuplicity");
        //poner parametros
        q.setParameter("name",staff.getName());
        q.setParameter("firstName",staff.getFirstName());
        q.setParameter("lastName",staff.getLastName());
        //ejecutar
        return !q.getResultList().isEmpty();
    }
}
